<?php

class BaseAdminController extends Controller
{

  protected function initialize()
  {
    $this->config()->set('theme', 'admin');
  }

  protected function beforeAction($action)
  {
    parent::beforeAction($action);

    if (! ($this->getName() == 'account' && in_array($action, array('login', 'logout')))) {
      Account::validate('admin');
    }
  }

  protected function callAction($action)
  {
    try {
      return parent::callAction($action);
    }
    catch (LoginRequiredException $e) {
      $this->response->redirect(array('/admin/account', array('action' => 'login')));
      $this->response->render();
    }
  }

}
